package simpleExample;

import org.objectweb.fractal.api.factory.InstantiationException;

import com.sun.corba.se.pept.transport.Connection;

import fr.ema.arch3d.editor.mainGUI.DrawGraph;
import fr.ema.arch3d.jmodel.assembly.Assembly;
import fr.ema.arch3d.jmodel.assembly.DefaultAssembly;
import fr.ema.arch3d.jmodel.configuration.Configuration;
import fr.ema.arch3d.jmodel.configuration.DefaultComponentClass;
import fr.ema.arch3d.jmodel.configuration.DefaultComponentType;
import fr.ema.arch3d.jmodel.configuration.DefaultConfiguration;
import fr.ema.arch3d.jmodel.configuration.DefaultConnectorClass;
import fr.ema.arch3d.jmodel.configuration.DefaultConnectorType;
import fr.ema.arch3d.jmodel.configuration.DefaultPrimitiveComponentClass;
import fr.ema.arch3d.jmodel.interfaceADL.DefaultInterface;
import fr.ema.arch3d.jmodel.specification.DefaultComponentRole;
import fr.ema.arch3d.jmodel.specification.DefaultConnection;
import fr.ema.arch3d.jmodel.specification.DefaultSpecification;
import fr.ema.arch3d.jmodel.specification.Specification;
import fr.ema.arch3d.transformer.transformModel.TransformJModelToREF;
import fr.ema.arch3d.transformer.transformModel.TransformJModelToREFImpl;
import fr.ema.arch3d.xoadl.configuration.ComponentClassADL;
import fr.ema.arch3d.xoadl.configuration.CompositeComponentClassADL;
import fr.ema.arch3d.xoadl.configuration.ConfigurationADL;
import fr.ema.arch3d.xoadl.configuration.ComponentTypeADL;
import fr.ema.arch3d.xoadl.configuration.ConnectorClassADL;
import fr.ema.arch3d.xoadl.configuration.PrimitiveComponentClassADL;
import fr.ema.arch3d.xoadl.configuration.impl.ConfigurationADLImpl;
import fr.ema.arch3d.xoadl.interfaceADL.InterfaceADL;
import fr.ema.arch3d.xoadl.specification.ComponentRoleADL;
import fr.ema.arch3d.xoadl.specification.ConnectionADL;

public class clientSever1 {

    /**
     * Method description
     *
     * @param args
     * @throws NoSuchDefaultInterfaceException 
     * @throws InstantiationException 
     */
    public static void main(String[] args) throws InstantiationException {
	InterfaceADL cItf1=new DefaultInterface("cItf1", "required", "example.log");
	InterfaceADL cItf2=new DefaultInterface("cItf2", "required", "example.log");
	InterfaceADL sItf1=new DefaultInterface("sItf1", "provided", "example.log");
	InterfaceADL sItf2=new DefaultInterface("sItf2", "provided", "example.log");
	ComponentRoleADL client=new DefaultComponentRole("client",new InterfaceADL[]{cItf1,cItf2},"!cItf1.findName1*|!cItf2.findName2*");
	ComponentRoleADL server1=new DefaultComponentRole("server1",new InterfaceADL[]{sItf1},"?sItf1.findName1*");
	ComponentRoleADL server2=new DefaultComponentRole("server2",new InterfaceADL[]{sItf2},"?sItf2.findName2*");
	
	ConnectionADL cs1=new DefaultConnection("cs1", "client", "cItf1", "server1", "sItf1");
	ConnectionADL cs2=new DefaultConnection("cs2", "client",  "cItf2", "server2", "sItf2");
	DefaultSpecification spec=new DefaultSpecification("clientServer", new ComponentRoleADL[]{client, server1, server2}, new ConnectionADL[]{cs1,cs2},null,"2.0","1.0");

//
//	SpecificationBehaviorConsistencyChecker.check(spec);
//	NameConsistencyChecker.check(spec, client);
	DefaultComponentType ct1=new DefaultComponentType("ct1",new InterfaceADL[]{cItf1,cItf2,sItf1},null);
	ComponentClassADL c1=new DefaultPrimitiveComponentClass("c1", ct1, "2.0", "1.0", new String[]{}, "example.log");
	ComponentClassADL s1=new DefaultPrimitiveComponentClass("s1", ct1, "2.0", "1.0", new String[]{}, "example.log");
	ConfigurationADLImpl.ComponentImplementationImpl ci1=new ConfigurationADLImpl.ComponentImplementationImpl();
	ci1.setComponentClassName("c1");
	ci1.setImplComponentRoleName("client");
	ConfigurationADLImpl.ComponentImplementationImpl ci2=new ConfigurationADLImpl.ComponentImplementationImpl();
	ci2.setComponentClassName("s1");
	ci2.setImplComponentRoleName("server1");
	
	DefaultConnectorType connectort1=new DefaultConnectorType("connectort1",new InterfaceADL[]{cItf1,sItf1},null);
	ConnectorClassADL connector1=new DefaultConnectorClass("connector1", connectort1,  "example.log", new String[]{});
	ConfigurationADLImpl.ConnectorImplementationImpl connectori1=new ConfigurationADLImpl.ConnectorImplementationImpl();
	connectori1.setConnectorClassName("connector1");
	connectori1.setImplConnectionName("cs1");

	Configuration config=new DefaultConfiguration("configruation", spec, new PrimitiveComponentClassADL []{ (PrimitiveComponentClassADL) c1, (PrimitiveComponentClassADL) s1},
		new CompositeComponentClassADL[]{},new ConnectorClassADL[]{connector1}, new ConfigurationADL.ComponentImplementation[]{ci1,ci2}, 
		new ConfigurationADL.ConnectorImplementation[]{connectori1});
	 System.out.println("edges==="+config.getConfigConnection().get(0).getProvidedCmpName());
	DrawGraph dg=new DrawGraph();
	//dg.drawArch(spec, config, null);
	DefaultAssembly ass=new DefaultAssembly();
	TransformJModelToREF t = new TransformJModelToREFImpl();
	t.transformAssembly(ass);
    }



}
